using System;
using System.Collections.Generic;
using System.Text;

namespace SideShow.Driver
{
    static class NativeMethods
    {
        public const int ERROR_NOT_SUPPORTED = 50;

        public const uint FILE_DEVICE_WPD = 0x00000040;
        public const uint WPD_CONTROL_FUNCTION_GENERIC_MESSAGE = 0x42;
        public const uint METHOD_BUFFERED = 0;
        public const uint FILE_READ_ACCESS = 0x0001;
        public const uint FILE_WRITE_ACCESS = 0x0002;

        public static readonly uint IOCTL_WPD_MESSAGE_READWRITE_ACCESS = CtlCode(FILE_DEVICE_WPD, WPD_CONTROL_FUNCTION_GENERIC_MESSAGE, METHOD_BUFFERED, (FILE_READ_ACCESS | FILE_WRITE_ACCESS));
        public static readonly uint IOCTL_WPD_MESSAGE_READ_ACCESS = CtlCode(FILE_DEVICE_WPD, WPD_CONTROL_FUNCTION_GENERIC_MESSAGE, METHOD_BUFFERED, FILE_READ_ACCESS);

        public static uint CtlCode(uint deviceType, uint function, uint method, uint access)
        {
            return (deviceType << 16) | ((access << 14) | (function << 2) | method);
        }

        public static bool IsWpdIoCtl(uint controlCode)
        {
            return (controlCode == IOCTL_WPD_MESSAGE_READWRITE_ACCESS) ||
                (controlCode == IOCTL_WPD_MESSAGE_READ_ACCESS);
        }
    
    }
}
